package com.mls.fivedistrict.server.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mls.fivedistrict.common.PageFilter;
import com.mls.fivedistrict.dao.AppVersionMapper;
import com.mls.fivedistrict.pojo.AppVersion;
import com.mls.fivedistrict.pojo.AppVersionExample;
import com.mls.fivedistrict.server.AppVersionService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lixixi on 2018/4/2.
 */
@Service("appVersionService")
public class AppVersionServiceImpl implements AppVersionService {

    @Resource(name = "appVersionMapper")
    AppVersionMapper appVersionMapper;

    @Override
    public AppVersion getNewestVersion() {
        AppVersionExample appVersionExample = new AppVersionExample();
        appVersionExample.setOrderByClause("app_version desc");
        List<AppVersion> appVersions = appVersionMapper.selectByExample(appVersionExample);
        if (appVersions.size() > 0) {
            return appVersions.get(0);
        }
        return null;
    }

    @Override
    public int insertVersion(AppVersion appVersion) {
        return appVersionMapper.insertSelective(appVersion);
    }

    @Override
    public PageInfo<AppVersion> getAllList(PageFilter pageFilter) {
        AppVersionExample appVersionExample = new AppVersionExample();
        PageHelper.startPage(pageFilter.getPageNum(), pageFilter.getPageSize());
        List<AppVersion> appVersionList = appVersionMapper.selectByExample(appVersionExample);
        PageInfo<AppVersion> appVersionPageInfo = new PageInfo<>(appVersionList);
        return appVersionPageInfo;
    }
}
